package cn.wjzhang.controller;

import cn.wjzhang.config.NavProperties;
import cn.wjzhang.service.NavCategoryService;
import cn.wjzhang.service.NavSiteService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.io.Writer;

/**
 * ========================
 * 凝夜紫导航
 *
 * @author wjzhang
 * @version v1.0
 * ========================
 * @date 2023/9/19 17:44
 */
@Controller
@RequiredArgsConstructor
@RequestMapping("/")
public class NavIndexController {

	private final NavProperties navProperties;
	private final NavCategoryService navCategoryService;
	private final NavSiteService navSiteService;

	/**
	 * 首页
	 *
	 * @return R
	 */
	@RequestMapping(value = {"/", "/index", "index.html"})
	public String redirect(HttpServletRequest request) {

		/* ====================================== header start ====================================== */
		request.setAttribute("title", navProperties.getTitle());
		request.setAttribute("keywords", navProperties.getKeywords());
		request.setAttribute("desc", navProperties.getDesc());
		/* ====================================== header end ====================================== */

		/* ====================================== 菜单 start ====================================== */
		request.setAttribute("navCategoryList", navCategoryService.treeCategory(null, null, null));
		/* ====================================== 菜单 end ====================================== */

		/* ====================================== 网址 start ====================================== */
		request.setAttribute("navSiteList", navSiteService.queryByGroup());
		/* ====================================== 网址 end ====================================== */

		/* ====================================== 底部 start ====================================== */


		/* ====================================== 底部 end ====================================== */
		return "index";
	}

	/**
	 * robots txt
	 *
	 * @return
	 */
	@GetMapping("/robots.txt")
	public void robotsTxt(HttpServletResponse response) throws IOException {
		Writer writer = response.getWriter();
		writer.append("User-agent: *\n");
		writer.append("Disallow:");
	}


}
